<?php
/*
 * Created on Aug 14, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
function _frontend_preset_share_advertisement_slide($view){
	static $start;
    static $rows;
    
    switch ($view['tag']) {
        case 'RECOMMEND':
        return _frontend_preset_share_advertisement_slide_recommand($start, $rows, false);
    }
}

function _frontend_preset_share_advertisement_slide_recommand($start, $rows, $pager){
    
    $query = db_select('node', 'n');
    
    $query->fields('n', array('nid', 'sticky', 'created'))
          ->condition('n.type', 'slideshow_ad')
          ->condition('n.status', 1)
          ->condition('n.promote', 1)
          ->orderBy('n.sticky', 'DESC')
          ->orderBy('n.created', 'DESC')
          ->addTag('node_access');
    
    $nids = $query->execute()->fetchCol();
    
    if (!empty($nids)) {
        $nodes = node_load_multiple($nids);
        $build = node_view_multiple($nodes, 'slide');
    } else {
        $build['#children'] =t('There is no product published.');
    }
    return $build;
}